<?php
class Poker extends AppModel {

	var $name = 'Poker';
	var $useTable = false;


	function deal($numPlayers = 2) {

		$numPlayerCards = $numPlayers * 2;

		$deck = $this->getDeck();

		$playersCards = array_slice($deck, 0, $numPlayerCards);

		for ($i = 0; $i < $numPlayers; $i++) {
			$c = $i + 1;
			$pCards[$c] = array($playersCards[$i], $playersCards[$i + $numPlayers]);
		}

		$data['players'] = $pCards;

		$flopPoint = $numPlayerCards + 1;

		$numFlop = 3;

		$data['flop'] = array_slice($deck, $flopPoint, $numFlop);

		$turnPoint = $flopPoint + $numFlop + 1;

		$numTurn = 1;

		$data['turn'] = array_slice($deck, $turnPoint, $numTurn);

		$riverPoint = $turnPoint + $numTurn + 1;

		$numRiver = 1;

		$data['river'] = array_slice($deck, $riverPoint, $numRiver);

		return $data;

	}

	function getDeck() {

		$leads = array('c', 'h', 'd', 's');
		$values = array('2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A');

		srand((float)microtime() * 1000000);
		shuffle($leads);
		shuffle($values);

		foreach ($leads as $lead) {
			foreach  ($values as $value) {
				$deck[] = $value.$lead;
			}
		}

		shuffle($deck);
		return $deck;
	}

}
?>
